package com.atguigu.day07;

import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.IOException;

public class Flink09_StateBackend {
    public static void main(String[] args) throws IOException {
        //1.获取流的执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //TODO 设置状态后端
        //TODO 内存
        //老版本设置方法
//        env.setStateBackend(new MemoryStateBackend());

        //1.13版本之后新版写法
        env.setStateBackend(new HashMapStateBackend());
        //指定CheckPoint状态存储
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());


        //TODO 文件级别
        //老版写法
//        env.setStateBackend(new FsStateBackend("hdfs://hadoop102:8020/..."));

       //1.13版本之后新版写法
        env.setStateBackend(new HashMapStateBackend());
//        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("file:///checkpoint-dir"));

        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/.....");

        //TODO RocksDB
        //老版
//        env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop102:8020/...."));

        //新版
        env.setStateBackend(new EmbeddedRocksDBStateBackend());
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/....");

        //TODO barrier不对齐
        env.getCheckpointConfig().enableUnalignedCheckpoints();
    }
}
